package com.glsc.ngateway.common.base.repo.mysql.gateway.platform.system;

import com.glsc.ngateway.common.base.domain.mysql.gateway.system.SystemMain;
import com.glsc.ngateway.common.base.domain.mysql.gateway.system.SystemMember;
import feign.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SystemMemberRepository extends JpaRepository<SystemMember, Integer>, JpaSpecificationExecutor<SystemMember> {
    @Query(value = "select m from SystemMember m where 1=1 " +
            "and (:#{#paramSearchDto.memberAccount} is null OR m.memberAccount = :#{#paramSearchDto.memberAccount})  " +
            "and (:#{#paramSearchDto.memberName} is null OR m.memberName LIKE CONCAT('%',:#{#paramSearchDto.memberName},'%') )  " +
//            "and (:#{#paramSearchDto.processDefineKey} is null OR m.processDefineKey = :#{#paramSearchDto.processDefineKey} )  " +
//            "and (:#{#paramSearchDto.systemCode} is null OR m.systemCode = :#{#paramSearchDto.systemCode} )  " +
//            "and (:#{#paramSearchDto.beginDateLocalDate} is null OR m.processCreateTime >= :#{#paramSearchDto.beginDateLocalDate} )  " +
//            "and (:#{#paramSearchDto.endDateLocalDate} is null OR m.processCreateTime <= :#{#paramSearchDto.endDateLocalDate} )  " +
//            "and (:#{#paramSearchDto.hasProcessEnd} is null OR m.isClose = :#{#paramSearchDto.hasProcessEnd} )  " +
//            "and (coalesce(:#{#paramSearchDto.adminList}, null) is null or m.systemAdminAccount in (:#{#paramSearchDto.adminList})) " +
            "and (:#{#paramSearchDto.deleted} is null OR m.deleted = :#{#paramSearchDto.deleted} )  " +
            "")
    List<SystemMember> searchByParam(SystemMember paramSearchDto);

    List<SystemMember> queryAllByDeletedAndOpId(@Param("deleted") Integer deleted,@Param("opId") Integer opId);

    @Query(value = "select a from SystemMember m inner join SystemMain a on m.opId = a.opId where 1=1 " +
            "and m.deleted = 0 and m.memberType = '1' and m.status = '1' " +
            "and m.memberAccount in (:account)  " +
            "")
    List<SystemMain> querySystemCodeByMemberAccount(@Param("account") List<String> account);

    List<SystemMember> findAllByMemberTypeAndMemberAccountInAndDeleted(String code, List<String> memberManager, Integer deleted);
}